<template>
  <svg :class="svgClass" v-bind="$attrs" :style="{ color: color }">
    <use :xlink:href="`#svg-icon-${props.name}`" />
  </svg>
</template>

<script setup name="SvgIcon">
import { computed } from 'vue'
const props = defineProps({
  name: {
    // 自定义svg的name属性
    type: String,
    required: true
  },
  color: {
    // 自定义svg的color属性
    type: String,
    default: ''
  }
})

const svgClass = computed(() => {
  if (props.name) {
    return `svg-icon svg-icon-${props.name}`
  }
  return 'svg-icon'
})
</script>

<style lang="less" scoped>
.svg-icon {
  width: 1.6em;
  height: 1.6em;
}
</style>
